// ==================================================================================
// Shared Genomics Project MPI Codebase
// Version 1.0 30/04/2010
//
// (c) 2010 University of Manchester all rights reserved
//
// This file is distributed under the GNU General Public License, Version 2.  
// Please see the file COPYING.txt for more details
// ==================================================================================

#ifndef _SPEDFILE_H_
#define _SPEDFILE_H_

#include "bmapfile.h"
#include "mapfile.h"
#include "options.h"

#ifdef __cplusplus
extern "C" {
#endif

/*!
\file
\ingroup	gio
\brief		SNP-Major Allelic Bitstring array 
\details
	A file containing an SNP-Major Allelic Bitstring array is referred as an SPED file
	in this documentation.<br>
	A SPED file has typically the suffix \ref SUFFIX_SPED_FILE.
*/

#define MAX_RS_TEXT_LENGTH 11 + 1 // One extra for the NULL character.

/*!
\brief Create a SPED file.
\details The path to the output file is bound to the variable \ref selected_options::szSpedFileName.
\param [in] map Source genomic data-set
\param [in] ops Location of the output file
\returns 1 on success, 0 on failure
*/
int spedfile_create(struct mapfile *map, struct selected_options *ops);

/*!
\brief Load an SPED file.
\details The path to the input file is bound to the variable \ref selected_options::szIpedFileName.
\param [in] ops Location of the input file
\param [in,out] nSNPs Pointer to store No. SNPs in a data-set.
\param [in,out] nSamples Pointer to store No. Samples/People in a data-set.
\param [in,out] nRecordBytes Bitstring size in bytes allocated to each SNP in a data-set.
\returns char/byte array or NULL on failure
*/
char* spedfile_load(struct selected_options *ops, int *nSNPs, int *nSamples, int *nRecordBytes);

/*!
\brief Create a SPED file and copy to a remote directory.
\details
	The output filename is a concatonation of \ref selected_options::rdir, \ref selected_options::szRunId
	and \ref SUFFIX_SPED_FILE .<br>
\param [in] ops Output file location
\param [in] m Genomic data-set to write to file
\param [in] rank Local processor rank
\returns 1 on success, 0 on failure
*/
int spedfile_create_and_copy(struct selected_options *ops, struct mapfile *m, int rank);

/*!
\brief Load an SPED file.
\details 
	The input filename is a concatonation of \ref selected_options::rdir, \ref selected_options::szRunId
	and \ref SUFFIX_SPED_FILE .<br>
\param [in] ops Location of the input file
\param [in,out] nSNPs Pointer to store No. SNPs in a data-set.
\param [in,out] nSamples Pointer to store No. Samples/People in a data-set.
\param [in,out] nRecordBytes Bitstring size in bytes allocated to each SNP in a data-set.
\returns char/byte array or NULL on failure
*/
char* _spedfile_load(struct selected_options *ops, int *nSNPs, int *nSamples, int *nRecordBytes);

int spedfile_to_ipedfile(struct selected_options *ops);

#ifdef __cplusplus
}
#endif

#endif // _SPEDFILE_H_
